package com.security.config.filter;

import com.security.system.dao.SysMenuDao;
import com.security.system.entity.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.stereotype.Component;
import org.springframework.util.AntPathMatcher;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Component("arbcServiceFilter")
public class ARBCServiceFilter {

    @Autowired
    SysMenuDao menuDao;

    AntPathMatcher antPathMatcher = new AntPathMatcher();

    public boolean hasPermission(HttpServletRequest req, Authentication auth){
        Object principal = auth.getPrincipal();
        System.out.println("arbcServiceFilter == " + req.getRequestURI());
        /*if (principal instanceof SysUser){
            SysUser user = (SysUser) principal;
            List<String> urls =  menuDao.getUrlByRid(user.getRoles().get(0).getRid().toString());
            return urls.stream().anyMatch(url->antPathMatcher.match(url,req.getRequestURI()));
        }*/
        return true;
    }

}
